package jumpingnotes.dao;

import java.io.Serializable;

public class Sorter implements Serializable
{
	private boolean ascending;

	private boolean ignoreCase;

	private String propertyName;

	/**
	 * Constructor for Sorter.
	 */
	protected Sorter(String propertyName, boolean ascending)
	{
		this.propertyName = propertyName;
		this.ascending = ascending;
	}

	/**
	 * Ascending sort
	 * 
	 * @param propertyName
	 * @return Sorter
	 */
	public static Sorter asc(String propertyName)
	{
		return new Sorter(propertyName, true);
	}

	/**
	 * Descending sort
	 * 
	 * @param propertyName
	 * @return Sorter
	 */
	public static Sorter desc(String propertyName)
	{
		return new Sorter(propertyName, false);
	}

	public String toString()
	{
		return propertyName + ' ' + (ascending ? "asc" : "desc");
	}

	public Sorter ignoreCase()
	{
		ignoreCase = true;
		return this;
	}

	public boolean isAscending()
	{
		return ascending;
	}

	public boolean isIgnoreCase()
	{
		return ignoreCase;
	}

	public String getPropertyName()
	{
		return propertyName;
	}
}
